home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / sampler4.arc / CROSSTAB.SAC < prev    next >
Encoding:
Text File  |  1985-08-30  |  13.4 KB  |  385 lines

  1. ON ECHO
  2.  
  3. !*******************************************************************!
  4. !                                                                   !
  5. !             Cross-section Techniques in SORITEC Sampler           !
  6. !                           (Chapter 8)                             !
  7. !                                                                   !
  8. !*******************************************************************!
  9. !   
  10. !    SORITEC Sampler provides two commands for analyzing cross-section
  11. !    data.  
  12. !    
  13. !    SYNOPSIS produces a detailed summary analysis of data series
  14. !    including mean, standard deviation, median, quartiles, deciles, 
  15. !    variance, skewness, kurtosis, coefficient of variation
  16. !    number of observations, number of missing values, minimum,
  17. !    range, mode and frequency of the mode.
  18. !    
  19. !    XTAB calculates a standard row * column crosstabulation report.
  20. !    Crosstabulation output can be controlled by the interactive
  21. !    print server if the ON CRT option is enabled.
  22. !    
  23. !    These commands are demonstrated using sample data drawn from
  24. !    Berenson, M.L., D.M. Levine and M. Goldstein, Intermediate
  25. !    Statistical Methods and Applications:  A Computer Package
  26. !    Approach.  Englewood Cliffs: Prentice-Hall, 1983, p. 30.  The
  27. !    data represent raw data derived from an hypothetical employee 
  28. !    questionnaire and were used to demonstrate features of various
  29. !    commercial statistical packages.  The data base contains the 
  30. !    sex, age, education, employment tenure, job class and weekly
  31. !    salary of 46 respondents.
  32. !    
  33. !    Read in the sample data.
  34. !    
  35.  
  36. USE 1 46
  37.  
  38. READ sex age education months_employed job_classification salary
  39.       1   40     3          207                2            458
  40.       0   21     2           25                1            235
  41.       1   49     2          390                3            798
  42.       1   45     3           34                2            339
  43.       1   25     5           20                2            339
  44.       1   47     4          209                3            584
  45.       1   22     3           15                2            296
  46.       1   22     3           12                2            235
  47.       1   28     4           70                2            235
  48.       1   57     3          475                3            571
  49.       0   20     2           31                2            283
  50.       1   50     3          364                2            403
  51.       0   51     3           31                1            363
  52.       1   62     2          416                2            436
  53.       1   32     2          129                2            435
  54.       1   51     4           42                1            334
  55.       1   55     4           89                2            455
  56.       0   45     2          274                1            293
  57.       1   31     5           15                1            228
  58.       1   62     2          372                2            379
  59.       1   54     2           83                2            339
  60.       0   42     2           98                2            270
  61.       1   26     4            4                2            303
  62.       1   38     4           43                2            340
  63.       1   32     2           85                2            359
  64.       1   45     4           26                2            334
  65.       1   28     3           99                2            314
  66.       1   42     4            8                2            340
  67.       1   50     2           82                2            373
  68.       1   44     4          211                3            581
  69.       1   35     4          137                2            451
  70.       1   68     2          128                2            323
  71.       1   40     5           18                2            345
  72.       1   24     5            5                2            333
  73.       0   27     4           21                1            296
  74.       1   46     5           87                2            363
  75.       0   63     3          102                2            325
  76.       1   28     5           60                2            363
  77.       1   64     1          338                2            323
  78.       1   51     2          351                2            323
  79.       1   47     1          101                2            323
  80.       0   22     3           28                1            256
  81.       1   51     5          317                3            515
  82.       1   29     5           31                3            411
  83.       1   48     4          316                3            544
  84.       1   59     5          293                3            450 ;
  85. END
  86.  
  87. cls
  88. !*******************************************************************!
  89. !                                                                   !
  90. !           Summary Statistics of Cross-section Data                !
  91. !                         (Section 8.1)                             !
  92. !                                                                   !
  93. !*******************************************************************!
  94. !    
  95. !    A summary analysis of any variable is produced by the SYNOPSIS
  96. !    command, i.e.,
  97. !    
  98.  
  99. SYNOPSIS age months_employed salary
  100.  
  101. !    
  102. !    All summary statistics produced at the terminal are stored as
  103. !    internal SORITEC variables and can be retrieved explicitly by
  104. !    the RECOVER command or referenced implicitly in command lines
  105. !    by prefixing the internal variable name with an up-carat(^).
  106. !    Internal variable names are stored as vectors with the same
  107. !    number of elements as arguments in the command line.  For example,
  108. !    recovering the means of the variables is accomplished with the
  109. !    command:
  110. !    
  111.  
  112. RECOVER mean_values MEANS
  113.  
  114. !    
  115. !    Print out the vector.
  116. !    
  117.  
  118. PRINT mean_values
  119.  
  120. !    
  121. !    Now if we want to access the mean of "months_employed" ...
  122. !    
  123.  
  124. SET mean_months_employed = mean_values(2)
  125. PRINT mean_months_employed
  126.  
  127. !    
  128. !    As another example, recover the vector of minimum values
  129. !    
  130.  
  131. RECOVER minimum_values MIN
  132.  
  133. !    
  134. !    Currently, deciles and quartiles are stored as vectors, meaning
  135. !    that SORITEC Sampler only retains decile and quartile values of
  136. !    the last variable in the argument list.  Therefore, after 
  137. !    executing the command:
  138. !    
  139.  
  140. RECOVER salary_quartiles QUARTIL
  141.  
  142. !    
  143. !    "quartile_values" contains statistics on the variable "salary".
  144. !    
  145.  
  146. PRINT salary_quartiles
  147.  
  148. !    
  149. !    Note that the same results would be produced by the command:
  150. !    
  151.  
  152. PRINT ^QUARTIL
  153.  
  154. !    
  155. !    We'll recover the quartile values for "months_employed" for the
  156. !    crosstabulation analysis below.  To retrieve the data, we must
  157. !    re-execute the SYNOPSIS command with "months_employed" as the
  158. !    last argument.
  159. !
  160.  
  161. SYNOPSIS months_employed
  162. RECOVER months_employed_quartiles QUARTIL
  163.  
  164. !    
  165. !    That's about it for the SYNOPSIS command.
  166. !
  167. cls
  168. !*******************************************************************!
  169. !                                                                   !
  170. !                     Crosstabulation Analysis                      !
  171. !                          (Section 8.2)                            !
  172. !                                                                   !
  173. !*******************************************************************!
  174. !    
  175. !    Crosstabulation tables are generated by the XTAB command in
  176. !    SORITEC Sampler.  Only a two-way table may be generated, meaning
  177. !    that only two arguments may follow the command name.  The
  178. !    data series must be DISCRETE data.  We'll show you later in this
  179. !    demo how to use the RECODE command to transform continuous to
  180. !    discrete data.
  181. !    
  182. !    Suppose we want to crosstabulate job classification with education.
  183. !    Both of these variables consist of discrete data with the following
  184. !    meanings:
  185. !    
  186. !    Job Classification: (1) clerical
  187. !                        (2) technical
  188. !                        (3) managerial
  189. !    
  190. !    Education: (1) non-high school graduate
  191. !               (2) high school graduate
  192. !               (3) post-high school education
  193. !               (4) 2-year college degree
  194. !               (5) 4-year college degree
  195. !    
  196. !    A crosstabulated table is produced by the command:
  197. !    
  198.  
  199. XTAB job_classification education
  200.  
  201. !    
  202. !    Note that the first argument is the row variable and the second is the
  203. !    column variable. 
  204. !    
  205. !    Recoverable internal SORITEC variables are: 
  206. !         NROW - the number of rows in the table
  207. !         NCOL - number of columns
  208. !         RMARGIN - vector containing row margin values
  209. !         CMARGIN - vector containing column values
  210. !         XTABLE - matrix of the inner table
  211. !    
  212. !    Note that the inner table is stored only when the NOMATS option
  213. !    is OFF (the default).
  214. !    
  215. !    The inner table can be printed directly by the command.
  216. !    
  217.  
  218. PRINT ^XTABLE
  219.  
  220. !    
  221. !    When data series are continuous, they must first be transformed into
  222. !    discrete values before they can be crosstabulated.  This is done
  223. !    in SORITEC Sampler with the RECODE command (Section 6.3).
  224. !    With the RECODE command, the arguments in the command line are
  225. !    the output data series, the input data series and the interval 
  226. !    boundaries over which you want the data categorized, ranging from 
  227. !    minimum to maximum values.  Interval boundaries may be numbers, 
  228. !    CONSTANTS or PARAMETERS.
  229. !    
  230. !    For example, suppose we want to crosstabulate sex versus salary,
  231. !    and months employed versus salary.  We'll use the quartiles and 
  232. !    minimums we saved from the SYNOPSIS command to define the quantiles
  233. !    and automate the procedure as much as possible.
  234. !    
  235. !    The first crosstabulation will be sex versus salary.
  236. !    
  237. !    First, recover the current USE period and store it for later use
  238. !    in the variable "use_period"
  239. !    
  240.  
  241. RECOVER use_period USE
  242.  
  243. !    
  244. !    Now define the quantiles, which we will call p1, p2, p3, p4 and p5
  245. !    as the GROUP "pgroup".
  246. !    
  247.  
  248. GROUP pgroup p1 p2 p3 p4 p5
  249.  
  250. !    
  251. !    Assign the minimum interval boundary, p1, to be the minimum salary
  252. !    of the sample, which we saved in the VECTOR "minimum_values".
  253. !    The minimum salary is the 3rd element of this vector.
  254. !    
  255.  
  256. SET p1 = minimum_values(3)
  257.  
  258. !    
  259. !    Since the interval boundaries in the RECODE command must be
  260. !    numbers, CONSTANTS or PARAMETERS, we can either extract individual
  261. !    elements from the vector of quartiles we will use for the other
  262. !    interval boundaries or explicitly reference each vector element
  263. !    in the RECODE argument list.  In the first crosstabulation, we'll
  264. !    extract the individual elements of the vector and assign them to
  265. !    CONSTANTS to demonstrate some of the tricks you can use when
  266. !    applying SORITEC Sampler.  In the second example, we'll take a 
  267. !    "short-cut" approach.
  268. !    
  269. !    In SORITEC, extraction of individual elements from data series
  270. !    is facilitated by the GETOBS command.  This command is not 
  271. !    supported by SORITEC Sampler, however.  We can still extract 
  272. !    individual elements and assign them to CONSTANTS with the 
  273. !    following set of commands.
  274. !    
  275. !    First, change the USE period to the length of the vector of quartiles.
  276. !    
  277.  
  278. USE 1 4
  279.  
  280. !    
  281. !    Then transform the vector into a data series.
  282. !    
  283.  
  284. temp = salary_quartiles
  285.  
  286. !    
  287. !    Lastly, set up a DOT-loop that sequentially assigns each element
  288. !    of the data series to the remaining interval boundaries for the
  289. !    RECODE command.
  290. !    
  291. !
  292. !    Initialize an index counter for accessing each element of the
  293. !    temporary data series, "temp"
  294. !
  295.  
  296. SET j = 0
  297.  
  298. DOT p2 p3 p4 p5
  299.  
  300. SET j = j + 1
  301.  
  302. !
  303. !    Reset the USE period to each element of the data series.
  304. !    
  305.  
  306. USE j
  307.  
  308. !    
  309. !    Assign an element of the data series to an interval boundary.
  310. !    
  311.  
  312. SET : = temp
  313.  
  314. ENDDOT
  315.  
  316. !    
  317. !    Print out the group to insure the correct values have been assinged
  318. !    to the interval boundaries.  (Refer to the interval boundaries as a
  319. !    group.)
  320. !
  321.  
  322. ON GROUP 
  323.  
  324. PRINT pgroup
  325.  
  326. !    
  327. !    Now restore the original USE period which we previously recovered.
  328. !    
  329.  
  330. USE use_period
  331.  
  332. !
  333. !    Check to be sure the original USE period has been restored.
  334. !
  335.  
  336. USE
  337.  
  338. !    And use the RECODE command to transform the continuous data series,
  339. !    "salary" to the discrete series "salary_levels".
  340. !    
  341.  
  342. RECODE salary_levels salary pgroup
  343.  
  344. !    
  345. !    Print out both variables.
  346. !    
  347.  
  348. PRINT salary salary_levels
  349.  
  350. !    
  351. !    Finally, crosstabulate sex versus salary_levels.
  352. !    Sex is defined 0 = female and 1 = male in the data.
  353. !    
  354.  
  355. XTAB sex salary_levels
  356.    
  357. !    
  358. !    Repeat the procedure for months employed versus salary.
  359. !    This time, however, reference the relevant elements of the
  360. !    vectors "Minimum_values" and "months_employed_quartiles"
  361. !    directly into the RECODE command line.
  362. !    
  363.  
  364. RECODE months_employed_intervals months_employed  minimum_values(2) &
  365.           months_employed_quartiles(1) months_employed_quartiles(2) &
  366.           months_employed_quartiles(3) months_employed_quartiles(4) 
  367.  
  368. !    
  369. !    Not as elegant, but it does the trick!  See?
  370. !    
  371.  
  372. PRINT months_employed months_employed_intervals
  373.  
  374. !    
  375. !    Now generate the crosstabulation table.
  376. !    
  377.  
  378. XTAB months_employed_intervals salary_levels
  379.  
  380. !    
  381. !    That's it!
  382. !    
  383. cls
  384. QUIT
  385.